{template '_header'}

<div class="page-header">
    当前位置：<span class="text-primary">{if !empty($item['id'])}编辑{else}添加{/if}文章</span>
</div>

<div class="page-content">
    <div class="page-sub-toolbar">
        <span class="">
            {ifp 'system.site.article.add'}
                <a class="btn btn-primary btn-sm" href="{php echo webUrl('system/site/article/add')}">添加新文章</a>
            {/if}
        </span>
    </div>
    <form {ife 'system.site.article' $item}action="" method="post"{/if} class="form-horizontal form-validate" enctype="multipart/form-data">
        <input type="hidden" name="id" value="{$item['id']}" />
        <div class="form-group">
            <label class="col-lg control-label">排序</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'system.site.article' $item}
                    <input type="text" name="displayorder" class="form-control" value="{$item['displayorder']}"/>
                    <span class='help-block'>数字越大，排名越靠前</span>
                {else}
                    <div class='form-control-static'>{$item['displayorder']}</div>
                {/if}
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg control-label must">文章分类</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'system.site.article' $item}
                    <select name='cate' id="cate" class='form-control select2'>
                        <option value=''></option>
                        {loop $category $k $c}
                            <option value='{$k}' {if $item['cate']==$k}selected{/if}>{$c['name']}</option>
                        {/loop}
                    </select>
                {else}
                    <div class='form-control-static'>{if empty($item['cate'])}暂时无分类{else}
                        {$category[$item['cate']]['name']}{/if}
                    </div>
                {/if}
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg control-label must">文章标题</label>
            <div class="col-sm-9 col-xs-12 ">
                {ife 'system.site.article' $item}
                    <input type="text" id='title' name="title" class="form-control" value="{$item['title']}" data-rule-required="true"/>
                {else}
                    <div class='form-control-static'>{$item['title']}</div>
                {/if}
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg control-label">作者</label>
            <div class="col-sm-9 col-xs-12 ">
                {ife 'system.site.article' $item}
                    <input type="text" name="author" class="form-control" value="{$item['author']}"/>
                {else}
                    <div class='form-control-static'>{$item['author']}</div>
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg control-label">文章列表图片</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'system.site.article' $item}
                    {php echo tpl_form_field_image2('thumb', $item['thumb'])}
                    <span class='help-block'>建议尺寸:640 * 350 , 请将所有幻灯片图片尺寸保持一致</span>
                {else}
                    {if !empty($item['thumb'])}
                        <a href='{php echo tomedia($item[' thumb'])}' target='_blank'>
                            <img src="{php echo tomedia($item['thumb'])}" style='width:100px;border:1px solid #ccc;padding:1px'/>
                        </a>
                    {/if}
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg control-label">文章内容</label>
            <div class="col-sm-9">
                {php echo tpl_ueditor('content',$item['content'])}
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg control-label">状态</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'system.site.article' $item}
                    <label class='radio-inline'><input type='radio' name='status' value='1' {if $item['status']==1}checked{/if} /> 显示</label>
                    <label class='radio-inline'><input type='radio' name='status' value='0' {if $item['status']==0}checked{/if} /> 隐藏</label>
                {else}
                    <div class='form-control-static'>{if empty($item['status'])}隐藏{else}显示{/if}</div>
                {/if}
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg control-label"></label>
            <div class="col-sm-9 col-xs-12">
                {ife 'system.site.article' $item}
                    <input type="submit" value="提交" class="btn btn-primary"/>
                {/if}
                <input type="button" name="back" onclick='history.back()' {ifp 'system.site.article.add|system.site.article.edit'}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
            </div>
        </div>
    </form>
</div>

<script language='javascript'>
    $('form').submit(function(){
        if ($("#cate").isEmpty()) {
            $('form').attr('stop',1);
            tip.msgbox.err("请填写内容分类!");
            return false;
        }
        $('form').removeAttr('stop');
        return true;
    });
</script>

{template '_footer'}